/**
 * 27/ott/2011
 */
package org.unisannio.interactive;

import it.unipr.ce.dsg.s2p.sip.Address;

import java.util.List;

import org.unisannio.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * @author fabiomelillo@gmail.com
 *
 */
public class AddressArrayAdapter extends ArrayAdapter {
	
	Activity context;
	int listaDaCreare=0;

	
	public AddressArrayAdapter(Activity context, int layout, List<Address> items){
		super(context, layout, items);
		this.context=context;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Address a=(Address) getItem(position);
		
		if(a==null)
			return null;
		View myview = convertView; //migliorare le prestazioni non ricaricando ogni volta
		
		if (myview==null){
			LayoutInflater inflater=context.getLayoutInflater();
			if (listaDaCreare==0)
				listaDaCreare=R.layout.addresses;
			myview = inflater.inflate(listaDaCreare, null);
		}
		
		
		TextView label = (TextView) myview.findViewById(R.id.textViewAddress);
		label.setText(a.toString());
		
		return myview;
	}

}
